/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DA;

import Entity.Artist;
import Control.DBConnector;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author theInterloper
 */
public class artistDA {

    public static void write(Artist artist) throws SQLException {
        
        int ID =            artist.getID();
        String USERNAME =   artist.getUSERNAME();
        String FIRSTNAME =  artist.getFIRSTNAME();
        String SECONDNAME = artist.getSECONDNAME();
        String EMAIL =      artist.getEMAIL();
        String PASSWORD =   artist.getPASSWORD();
        String ADDRESS1 =   artist.getADDRESS1();
        String ADDRESS2 =   artist.getADDRESS2();
        String ADDRESS3 =   artist.getADDRESS3();
        String PHONE =      artist.getPHONE();
        String DESCRIPTION =artist.getDESCRIPTION();
        
        String insertArtist = "INSERT INTO artist (artistUserName,artistFirstName,artistSecondName,artistEmail,artistPassword,artistAddress1,artistAddress2,artistAddress3,artistPhoneNumber,artistDescription) VALUES "
                + "('"+ USERNAME + "','" + FIRSTNAME + "','" + SECONDNAME + "','" + EMAIL + "','" + PASSWORD + "','" + ADDRESS1 + "','" + ADDRESS2 + "','" + ADDRESS3 + "','" + PHONE + "','"+ DESCRIPTION + "');";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
        statement.execute(insertArtist);

    }

    public static Artist read(int i) throws SQLException {
         
        String getByID = "select * from artist where artistID = '" + i + "'";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
         
        ResultSet resultset = statement.executeQuery(getByID);
        
        Artist artist = new Artist();
        
        while(resultset.next()){
            artist.setID(resultset.getInt(1));
            artist.setUSERNAME(resultset.getString(2));
            artist.setFIRSTNAME(resultset.getString(3));
            artist.setSECONDNAME(resultset.getString(4));
            artist.setEMAIL(resultset.getString(5));
            artist.setPASSWORD(resultset.getString(6));
            artist.setADDRESS1(resultset.getString(7));
            artist.setADDRESS2(resultset.getString(8));
            artist.setADDRESS3(resultset.getString(9));
            artist.setPHONE(resultset.getString(10));
            artist.setDESCRIPTION(resultset.getString(11));
        } 
        return artist;
    }

    public static Artist readByUserName(String userName) throws SQLException {
        String getByUserName = "select * from artist where artistUserName = '" + userName + "'";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
         
        ResultSet resultset = statement.executeQuery(getByUserName);
        
        Artist artist = new Artist();
        
        while(resultset.next()){
            artist.setID(resultset.getInt(1));
            artist.setUSERNAME(resultset.getString(2));
            artist.setFIRSTNAME(resultset.getString(3));
            artist.setSECONDNAME(resultset.getString(4));
            artist.setEMAIL(resultset.getString(5));
            artist.setPASSWORD(resultset.getString(6));
            artist.setADDRESS1(resultset.getString(7));
            artist.setADDRESS2(resultset.getString(8));
            artist.setADDRESS3(resultset.getString(9));
            artist.setPHONE(resultset.getString(10));
            artist.setDESCRIPTION(resultset.getString(11));
        } 
        return artist;
    }

    public static Collection findAllArtists() throws SQLException {
        
        String getAll = "select * from artist";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
         
        ResultSet resultset = statement.executeQuery(getAll);
        Artist artist = new Artist();
        Collection artistCollection = new ArrayList<Artist>();
         
        return artistCollection;
    }
}
